#ifndef __BATTLE__SCENE_H__
#define __BATTLE__SCENE_H__

#include "cocos2d.h"
#include "CCTouch.h"
#include "BattleField.h"
#include "PlayerProfile.h"

namespace cocos2d
{
	class CCTMXTiledMap;
	class CCSprite;
	class CCTouch;
	class CCEvent;
}

enum
{
	LOCALPLAYER_GRID = 0,
	AIPLAYER_GRID = 0,
};



class BattleGrid;


class BattleScene : public cocos2d::CCLayer,public PlayerProfileListener
{
public:
	BattleScene();
	// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
	virtual bool init();  

	// there's no 'id' in cpp, so we recommand to return the exactly class pointer
	static cocos2d::CCScene* scene();
	
	// a selector callback
	virtual void menuAttackCallback(cocos2d::CCObject* pSender);
	virtual void menuSupplyCallback(cocos2d::CCObject* pSender);
	//virtual void menuSwitchCallback(cocos2d::CCObject* pSender);

	virtual void ccTouchesBegan(cocos2d::CCSet *pTouch, cocos2d::CCEvent *pEvent);
	virtual void ccTouchesMoved(cocos2d::CCSet *pTouch, cocos2d::CCEvent *pEvent);
	virtual void ccTouchesEnded(cocos2d::CCSet *pTouch, cocos2d::CCEvent *pEvent);

	virtual void onEnter();
	virtual void onExit();


	// implement the "static node()" method manually
	LAYER_CREATE_FUNC(BattleScene);

	virtual void update(float dt);

	void goToState(BattleState s);
	BattleState getState()const{
		return m_state;
	}

	virtual void tellActionNumChanged(int actionNum);

private:
	BattleField* m_battleField[BattleField_Num];
	BattleGrid* m_opGrid;
	cocos2d::CCTMXTiledMap* m_map;
	cocos2d::CCSprite*	m_opSprite;
	bool m_isOperatiorAction;
	BattleState m_state;
	int m_battleMargin;
	bool m_holdTouch;
	float m_holdTouchElapsedTime;
	cocos2d::CCPoint m_touchBeginPos;
	cocos2d::CCMenuItemFont* m_actionNumMenuItem;

	cocos2d::CCPoint computeTileCoordinate(const cocos2d::CCPoint& pos);
	bool canMouseActionThisTile(const cocos2d::CCPoint& pos);
	void releaseBattleField();

	BattleField* m_playerField;
	BattleField* m_enemyField;
	bool m_finishCheckA;
	bool m_swapTrun;
};

#endif // __HELLOWORLD_SCENE_H__
